// pages/serviceEval/serviceEval.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    eval:[
      // {id:1,orderid:32489565655656,sumper:45,tel:14578651245,state:1,tag:1,address:'广州市番禺区石岗路地址地址地址地址地址',user:'刘德华',active:3,time:'2020/09/06'},
    ],
    value: 0,
    type:null,
    textArea:'',//输入信息
    submitbtn:true,
    markname:'待服务',
    select: [{name: '服务有礼',index: 0}, {name: '专业讲师',index: 0}, {name: '最佳指导',index: 0}],
    Model:false,
     hiddenmodalput:true,
  },
  //标签多选
  // checkbox: function (e) {
  //   var index = e.currentTarget.dataset.index;//获取当前点击的下标
  //   var checkboxArr = this.data.checkboxArr;//选项集合
  //   checkboxArr[index].checked = !checkboxArr[index].checked;//改变当前选中的checked值
  //   this.setData({
  //    checkboxArr: checkboxArr
  //   });
  //  },
  onChange(event) {this.setData({value: event.detail,});},
  //点击弹出
	modalinput(){
		this.setData({hiddenmodalput: !this.data.hiddenmodalput})
  },
  choose(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    console.log(index)
    var select = this.data.select;
    if (select[index].index != 1) {
      select[index].index = 1
    } else {
      select[index].index = 0
    }
    that.setData({
      select: select
    })
    console.log(select)
  },
  customize(e) {
    var that = this;
    that.setData({
      customize:e.detail.value
    })
  },
  showModel(e) {
    var that = this;
    that.setData({
      Model:true,
      customize:''
    })
      },
  //取消按钮
  cancel: function(){this.setData({hiddenmodalput: true});},
  //确认
  confirm: function(){this.setData({hiddenmodalput: true})},
  //文字评论
  bindTextAreaBlur: function(e) {this.setData({ textArea : e.detail.value })},
  submit(e){
    let that = this;
    var i = e.currentTarget.dataset.status;//订单状态
    var type = that.data.type;
    let rate = that.data.value;
    let texteare = that.data.textArea;
    let json = { pk : that.data.eval.id}
    let data = {
      rate: rate,
      comment: texteare
    }
    // console.log(i)
    if(i==2){
      if(!data.rate&&!data.comment){
        wx.showToast({
          title: '你没有填写评价哦',
          icon: 'none',
          duration: 1500
        })
        return false //阻止发起请求
      }
      switch(type){
        case 1: //优选
        app.ports.api60({json,data}).then((res)=>{
            // console.log(res)
            wx.showToast({
              title: '评价成功',
              icon: 'success',
              duration: 1500
            })
          }).catch(()=>{console.error('评论错误！')});break
        case 2: //折扣
        app.ports.api61({json,data}).then((res)=>{
          // console.log(res)
          wx.showToast({
            title: '评价成功',
            icon: 'success',
            duration: 1500
          })
        }).catch(()=>{console.error('评论错误！')});break
        case 3: //放盘
        app.ports.api62({json,data}).then((res)=>{
          // console.log(res)
          wx.showToast({
            title: '评价成功',
            icon: 'success',
            duration: 1500
          })
        }).catch(()=>{console.error('评论错误！')});break
        case 4: //尽调
        app.ports.api63({json,data}).then((res)=>{
          // console.log(res)
          wx.showToast({
            title: '评价成功',
            icon: 'success',
            duration: 1500
          })
        }).catch(()=>{console.error('评论错误！')});break
        case 5: //好房
        app.ports.api64({json,data}).then((res)=>{
          // console.log(res)
          wx.showToast({
            title: '评价成功',
            icon: 'success',
            duration: 1500
          })
        }).catch(()=>{console.error('评论错误！')});break
        case 6: //增值
        app.ports.api65({json,data}).then((res)=>{
          // console.log(res)
          wx.showToast({
            title: '评价成功',
            icon: 'success',
            duration: 1500
          })
        }).catch(()=>{console.error('评论错误！')});break
      }
    }else{
      wx.showToast({
        title: '订单还没成功！无法评价',
        icon: 'none',
        duration: 1500
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log( options, "=======11111222222")
    let that = this;
    let type = Number(options.type);
    this.setData({type :type})
    let data = {  pk:options.id }
    switch(type){
      case 1: //优选预约
      getApp().ports.api2({data:data}).then((res) => {
          // console.log( options, "=======11111")
          let list = res.data;
          if(list.rate&&list.comment){
            that.setData({ submitbtn : false})
            that.setData({ value : list.rate });//获取评论数据
            that.setData({ texteare : list.comment });
          }
          res.data.orderTime = options.time.substring(0,10);
          if(options.telphone == 'null'|| options.telphone == 'undefined'){list.telphone = false}else{ list.telphone = options.telphone}
          if(options.markName == 'null'|| options.markName =='undefined'||options.markName ==''){
            list.markname = '待服务';
          }else{
            list.markname = options.markName;
          }
          list.arr = options.time.substring(5,16).split(" ");
          if(list.foreclosedHouse.startTime) list.arr1 = list.foreclosedHouse.startTime.substring(5,16).split(" ");
          if(list.foreclosedHouse.endTime) list.arr2 = list.foreclosedHouse.endTime.substring(5,16).split(" ");
          this.setData({eval:list})
        }).catch(() => {console.info('优选预约点击页面出错了？');});break;
      case 2://折扣 
      getApp().ports.api6({data:data}).then((res) => {
          // console.log(res.data);
          let dataList = res.data;
          if(dataList.rate&&dataList.comment){
            that.setData({ submitbtn : false})
            that.setData({ value : dataList.rate });//获取评论数据
            that.setData({ texteare : dataList.comment });
          }
          if(options.telphone == 'null'|| options.telphone == 'undefined'){dataList.telphone = false}else{ dataList.telphone = options.telphone}
          if(options.markName == 'null'|| options.markName =='undefined'||options.markName ==''){
            dataList.markname = '待服务';
          }else{
            dataList.markname = options.markName;
          }
          dataList.orderTime = options.time.substring(0,10);
          dataList.arr = options.time.substring(5,16).split("T");
          if(res.data.serving_time) dataList.arr1 = res.data.serving_time.split(" ");
          if(res.data.finish_time) dataList.arr2 = res.data.finish_time.split(" ");
          this.setData({eval:dataList})
        }).catch(() => {console.error('出啥错了？');});break;
      case 3://放盘
      getApp().ports.api9({data:data}).then((res) => {
          let datalist = res.data;
          // console.log(datalist);
        if(datalist.rate&&datalist.comment){
          that.setData({ submitbtn : false})
          that.setData({ value : datalist.rate });//获取评论数据
          that.setData({ texteare : datalist.comment });
        }
          if(options.telphone == 'null'|| options.telphone == 'undefined'){datalist.telphone = false}else{ datalist.telphone = options.telphone}
          if(options.markName == 'null'|| options.markName =='undefined'||options.markName ==''){
            datalist.markname = '待服务';
          }else{
            datalist.markname = options.markName;
          }
          datalist.arr = options.time.substring(5,16).split("T");
          datalist.orderTime = options.time.substring(0,10);
          if(datalist.serving_time) datalist.arr1 = datalist.serving_time.substring(5,16).split("T");
          if(datalist.finish_time) datalist.arr2 = datalist.finish_time.substring(5,16).split("T");
          this.setData({eval:datalist})
        }).catch(() => {console.error('放盘错了？')});break;
      case 4://尽调 
      getApp().ports.api16({data:data}).then((res) => {
        let datalist = res.data;
  //       console.log(datalist);
        if(datalist.rate&&datalist.comment){
          that.setData({ submitbtn : false})
          that.setData({ value : datalist.rate });//获取评论数据
          that.setData({ texteare : datalist.comment });
        }
        if(options.telphone == 'null'|| options.telphone == 'undefined'){datalist.telphone = false}else{ datalist.telphone = options.telphone}
        if(options.markName == 'null'|| options.markName =='undefined'||options.markName ==''){
          datalist.markname = '待服务';
        }else{
          datalist.markname = options.markName;
        }
        datalist.arr = options.time.substring(5,16).split("T");
        datalist.orderTime = options.time.substring(0,10);
        if(datalist.foreclosed_house.start_time) datalist.arr1 = datalist.foreclosed_house.start_time.substring(5,16).split("T");
        if(datalist.foreclosed_house.end_time) datalist.arr2 = datalist.foreclosed_house.end_time.substring(5,16).split("T");
        this.setData({eval:datalist})
      }).catch(() => {console.error('尽调错了？')});break;
      case 5://好房 
      getApp().ports.api12({data:data}).then((res) => {
        let datalist = res.data;
  //       console.log(datalist);
        if(datalist.rate&&datalist.comment){
          that.setData({ submitbtn : false})
          that.setData({ value : datalist.rate });//获取评论数据
          that.setData({ texteare : datalist.comment });
        }
        if(options.telphone == 'null'|| options.telphone == 'undefined'){datalist.telphone = false}else{ datalist.telphone = options.telphone}
        if(options.markName == 'null'|| options.markName =='undefined'||options.markName ==''){
          datalist.markname = '待服务';
        }else{
          datalist.markname = options.markName;
        }
        datalist.zdyTitle = '好房预约';
        datalist.arr = options.time.substring(5,16).split("T");
        datalist.orderTime = options.time.substring(0,10);
        if(res.data.serving_time) res.data.arr1 = res.data.serving_time.split(" ");
        if(res.data.finish_time) res.data.arr2 = res.data.finish_time.split(" ");
        this.setData({eval:datalist})
      }).catch(() => {console.error('好房错了？')});break;
      case 6://增值 
      getApp().ports.api14({data:data}).then((res) => {
        let datalist = res.data;
  //       console.log(datalist);
        if(datalist.rate&&datalist.comment){
          that.setData({ submitbtn : false})
          that.setData({ value : datalist.rate });//获取评论数据
          that.setData({ texteare : datalist.comment });
        }
  if(options.telphone == 'null'|| options.telphone == 'undefined'){datalist.telphone = false}else{ datalist.telphone = options.telphone}
        if(options.markName == 'null'|| options.markName =='undefined'||options.markName ==''){
          datalist.markname = '待服务';
        }else{
          datalist.markname = options.markName;
        }
        datalist.zdyTitle = '增值预约';
        datalist.arr = options.time.substring(5,16).split("T");
        datalist.orderTime = options.time.substring(0,10);
        if(datalist.serving_time) datalist.arr1 = datalist.serving_time.substring(5,16).split("T");
        if(datalist.finish_time) datalist.arr2 = datalist.finish_time.substring(5,16).split("T");
        this.setData({eval:datalist})
      }).catch(() => {console.error('增值错了？')});break;
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  
})